﻿<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
      <title>ProtoBufHelper 类
 | Fantasy.Net API Reference </title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="title" content="ProtoBufHelper 类
 | Fantasy.Net API Reference ">
      
      <link rel="icon" href="../favicon.ico">
      <link rel="stylesheet" href="../public/docfx.min.css">
      <link rel="stylesheet" href="../public/main.css">
      <meta name="docfx:navrel" content="../toc.html">
      <meta name="docfx:tocrel" content="toc.html">
      
      <meta name="docfx:rel" content="../">
      
      
      
  </head>

  <script type="module">
    import options from './../public/main.js'
    import { init } from './../public/docfx.min.js'
    init(options)
  </script>

  <script>
    const theme = localStorage.getItem('theme') || 'auto'
    document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
  </script>

  <body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
    <header class="bg-body border-bottom">
      <nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
        <div class="container-xxl flex-nowrap">
          <a class="navbar-brand" href="../index.html">
            <img id="logo" class="svg" src="../logo.svg" alt="Fantasy.Net">
            Fantasy.Net
          </a>
          <button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
            <i class="bi bi-three-dots"></i>
          </button>
          <div class="collapse navbar-collapse" id="navpanel">
            <div id="navbar">
              <form class="search" role="search" id="search">
                <i class="bi bi-search"></i>
                <input class="form-control" id="search-query" type="search" disabled="" placeholder="搜索" autocomplete="off" aria-label="Search">
              </form>
            </div>
          </div>
        </div>
      </nav>
    </header>

    <main class="container-xxl">
      <div class="toc-offcanvas">
        <div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body">
            <nav class="toc" id="toc"></nav>
          </div>
        </div>
      </div>

      <div class="content">
        <div class="actionbar">
          <button class="btn btn-lg border-0 d-md-none" style="margin-top: -.65em; margin-left: -.8em" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
            <i class="bi bi-list"></i>
          </button>

          <nav id="breadcrumb"></nav>
        </div>

        <article data-uid="Fantasy.ProtoBufHelper">



  <h1 id="Fantasy_ProtoBufHelper" data-uid="Fantasy.ProtoBufHelper" class="text-break">
    ProtoBufHelper 类
  
  </h1>

  <div class="facts text-secondary">
    <dl><dt>命名空间</dt><dd><a class="xref" href="Fantasy.html">Fantasy</a></dd></dl>
  <dl><dt>程序集</dt><dd>Fantasy.Net.dll</dd></dl>
  </div>

  <div class="markdown summary"><p>提供ProtoBuf序列化和反序列化的帮助方法类。</p>
</div>
  <div class="markdown conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static class ProtoBufHelper</code></pre>
  </div>




  <dl class="typelist inheritance">
    <dt>继承</dt>
    <dd>
      <div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
      <div><span class="xref">ProtoBufHelper</span></div>
    </dd>
  </dl>



  <dl class="typelist derived">
    <dt>继承成员</dt>
    <dd>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
    </div>
  </dd></dl>






  <h2 class="section" id="methods">方法
</h2>


  <a id="Fantasy_ProtoBufHelper_Clone_" data-uid="Fantasy.ProtoBufHelper.Clone*"></a>

  <h3 id="Fantasy_ProtoBufHelper_Clone__1___0_" data-uid="Fantasy.ProtoBufHelper.Clone``1(``0)">
  Clone&lt;T&gt;(T)
  
  </h3>

  <div class="markdown level1 summary"><p>克隆一个对象，通过序列化和反序列化实现深度复制。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static T Clone&lt;T&gt;(T t)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>t</code> <span class="xref">T</span></dt>
    <dd><p>要克隆的对象。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><span class="xref">T</span></dt>
    <dd><p>克隆后的新对象。</p>
</dd>
  </dl>

  <h4 class="section">类型参数</h4>
  <dl class="parameters">
    <dt><code>T</code></dt>
    <dd><p>要克隆的对象类型。</p>
</dd>
  </dl>










  <a id="Fantasy_ProtoBufHelper_FromBytes_" data-uid="Fantasy.ProtoBufHelper.FromBytes*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromBytes_System_Type_System_Byte___System_Int32_System_Int32_" data-uid="Fantasy.ProtoBufHelper.FromBytes(System.Type,System.Byte[],System.Int32,System.Int32)">
  FromBytes(Type, byte[], int, int)
  
  </h3>

  <div class="markdown level1 summary"><p>从指定的字节数组中的指定范围反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static object FromBytes(Type type, byte[] bytes, int index, int count)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>type</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
    <dt><code>bytes</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
    <dd><p>包含对象序列化数据的字节数组。</p>
</dd>
    <dt><code>index</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
    <dd><p>要反序列化数据的起始索引。</p>
</dd>
    <dt><code>count</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
    <dd><p>要反序列化的字节数据长度。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>











  <a id="Fantasy_ProtoBufHelper_FromBytes_" data-uid="Fantasy.ProtoBufHelper.FromBytes*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromBytes__1_System_Byte___" data-uid="Fantasy.ProtoBufHelper.FromBytes``1(System.Byte[])">
  FromBytes&lt;T&gt;(byte[])
  
  </h3>

  <div class="markdown level1 summary"><p>从字节数组中反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static T FromBytes&lt;T&gt;(byte[] bytes)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>bytes</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
    <dd><p>包含对象序列化数据的字节数组。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><span class="xref">T</span></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>

  <h4 class="section">类型参数</h4>
  <dl class="parameters">
    <dt><code>T</code></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
  </dl>










  <a id="Fantasy_ProtoBufHelper_FromBytes_" data-uid="Fantasy.ProtoBufHelper.FromBytes*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromBytes__1_System_Byte___System_Int32_System_Int32_" data-uid="Fantasy.ProtoBufHelper.FromBytes``1(System.Byte[],System.Int32,System.Int32)">
  FromBytes&lt;T&gt;(byte[], int, int)
  
  </h3>

  <div class="markdown level1 summary"><p>从指定的字节数组中的指定范围反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static T FromBytes&lt;T&gt;(byte[] bytes, int index, int count)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>bytes</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
    <dd><p>包含对象序列化数据的字节数组。</p>
</dd>
    <dt><code>index</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
    <dd><p>要反序列化数据的起始索引。</p>
</dd>
    <dt><code>count</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
    <dd><p>要反序列化的字节数据长度。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><span class="xref">T</span></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>

  <h4 class="section">类型参数</h4>
  <dl class="parameters">
    <dt><code>T</code></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
  </dl>










  <a id="Fantasy_ProtoBufHelper_FromMemory_" data-uid="Fantasy.ProtoBufHelper.FromMemory*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromMemory_System_Type_System_Memory_System_Byte__" data-uid="Fantasy.ProtoBufHelper.FromMemory(System.Type,System.Memory{System.Byte})">
  FromMemory(Type, Memory&lt;byte&gt;)
  
  </h3>

  <div class="markdown level1 summary"><p>从 Memory/byte 中反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static object FromMemory(Type type, Memory&lt;byte&gt; memory)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>type</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
    <dt><code>memory</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.memory-1">Memory</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>&gt;</dt>
    <dd><p>要反序列化的内存数据。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>











  <a id="Fantasy_ProtoBufHelper_FromSpan_" data-uid="Fantasy.ProtoBufHelper.FromSpan*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromSpan_System_Type_System_Span_System_Byte__" data-uid="Fantasy.ProtoBufHelper.FromSpan(System.Type,System.Span{System.Byte})">
  FromSpan(Type, Span&lt;byte&gt;)
  
  </h3>

  <div class="markdown level1 summary"><p>从 Span/byte 中反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static object FromSpan(Type type, Span&lt;byte&gt; span)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>type</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
    <dt><code>span</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.span-1">Span</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>&gt;</dt>
    <dd><p>要反序列化的字节数据。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>











  <a id="Fantasy_ProtoBufHelper_FromStream_" data-uid="Fantasy.ProtoBufHelper.FromStream*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromStream_System_Type_System_IO_MemoryStream_" data-uid="Fantasy.ProtoBufHelper.FromStream(System.Type,System.IO.MemoryStream)">
  FromStream(Type, MemoryStream)
  
  </h3>

  <div class="markdown level1 summary"><p>从指定的流中反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static object FromStream(Type type, MemoryStream stream)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>type</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
    <dt><code>stream</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.memorystream">MemoryStream</a></dt>
    <dd><p>包含对象序列化数据的流。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>











  <a id="Fantasy_ProtoBufHelper_FromStream_" data-uid="Fantasy.ProtoBufHelper.FromStream*"></a>

  <h3 id="Fantasy_ProtoBufHelper_FromStream__1_System_IO_MemoryStream_" data-uid="Fantasy.ProtoBufHelper.FromStream``1(System.IO.MemoryStream)">
  FromStream&lt;T&gt;(MemoryStream)
  
  </h3>

  <div class="markdown level1 summary"><p>从指定的流中反序列化对象。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static T FromStream&lt;T&gt;(MemoryStream stream)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>stream</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.memorystream">MemoryStream</a></dt>
    <dd><p>包含对象序列化数据的流。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><span class="xref">T</span></dt>
    <dd><p>反序列化得到的对象。</p>
</dd>
  </dl>

  <h4 class="section">类型参数</h4>
  <dl class="parameters">
    <dt><code>T</code></dt>
    <dd><p>要反序列化的对象类型。</p>
</dd>
  </dl>










  <a id="Fantasy_ProtoBufHelper_ToBytes_" data-uid="Fantasy.ProtoBufHelper.ToBytes*"></a>

  <h3 id="Fantasy_ProtoBufHelper_ToBytes_System_Object_" data-uid="Fantasy.ProtoBufHelper.ToBytes(System.Object)">
  ToBytes(object)
  
  </h3>

  <div class="markdown level1 summary"><p>将对象序列化为字节数组。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static byte[] ToBytes(object message)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>message</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>要序列化的对象。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
    <dd><p>包含序列化数据的字节数组。</p>
</dd>
  </dl>











  <a id="Fantasy_ProtoBufHelper_ToMemory_" data-uid="Fantasy.ProtoBufHelper.ToMemory*"></a>

  <h3 id="Fantasy_ProtoBufHelper_ToMemory_System_Object_System_Memory_System_Byte__" data-uid="Fantasy.ProtoBufHelper.ToMemory(System.Object,System.Memory{System.Byte})">
  ToMemory(object, Memory&lt;byte&gt;)
  
  </h3>

  <div class="markdown level1 summary"><p>将对象序列化到指定的内存中。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static void ToMemory(object message, Memory&lt;byte&gt; memory)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>message</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>要序列化的对象。</p>
</dd>
    <dt><code>memory</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.memory-1">Memory</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>&gt;</dt>
    <dd><p>目标内存。</p>
</dd>
  </dl>












  <a id="Fantasy_ProtoBufHelper_ToStream_" data-uid="Fantasy.ProtoBufHelper.ToStream*"></a>

  <h3 id="Fantasy_ProtoBufHelper_ToStream_System_Object_System_IO_MemoryStream_" data-uid="Fantasy.ProtoBufHelper.ToStream(System.Object,System.IO.MemoryStream)">
  ToStream(object, MemoryStream)
  
  </h3>

  <div class="markdown level1 summary"><p>将对象序列化到指定的流中。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static void ToStream(object message, MemoryStream stream)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>message</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></dt>
    <dd><p>要序列化的对象。</p>
</dd>
    <dt><code>stream</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.memorystream">MemoryStream</a></dt>
    <dd><p>目标流。</p>
</dd>
  </dl>













</article>


        
      </div>

      <div class="affix">
        <nav id="affix"></nav>
      </div>
    </main>

    <div class="container-xxl search-results" id="search-results"></div>

    <footer class="border-top">
      <div class="container-xxl">
        <div class="flex-fill">
          <span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
        </div>
      </div>
    </footer>
  </body>
</html>